{extend name="ashippingmanagement/Public/base" /}
{block name="container"}
    <style>
         .radio-inline input[type=radio] {
    margin-top: 4px;
}
    </style>
<div style="margin:20px">
    <form id="form_id" action="" class="form-inline">
        <table class="row-margin-top tab-content table-bordered  table" border="1" style="margin-bottom: 0">
            <input type="hidden" name="id" value="{$data['id']}">
            <tr>
                <td class="text-right" style="min-width: 160px;width: 160px" id="a">发运日期<span class="colorRed">*</span>:
                </td>
                <td><input type="text" class="form-control layer-date validate[required,custom[date]]"
                           name="fyDate" id="fyDate" value="{$data['fyDate']}"></td>
            </tr>
            <tr>
                <td class="text-right" style="min-width: 160px;width: 160px">售达方经销商名称<span class="colorRed">*</span>:
                </td>
                <td>
                    <div class="col-xs-4">
                        <div class="input-group">
                            <input type="text" class="form-control validate[required]" value="{$data['jxs']}" name="sdAgency" id="sdAgency"
                                   placeholder="请输入关键字或空格查询">
                            <div class="input-group-btn">
                                <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                </ul>
                            </div>
                        </div>
                    </div>
                    <input type="hidden" name="sdAgency_id" id="sdAgency_id" value="{$data['sdAgency_id']}">
                    <div class="col-xs-2">
                        <input type="button" class="btn btn-primary" id="selectSdAgency" value="选择"/>
                    </div>
                </td>
            </tr>
            <tr>
                <td class="text-right" style="min-width: 160px;width: 160px">售达方网点名称:</td>
                <td>
                    <div class="col-xs-4">
                        <div class="input-group">
                            <input type="text" class="form-control" value="{$data['wd']}" name="sdNet" id="sdNet"
                                   placeholder="请选择">
                            <div class="input-group-btn">
                                <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                </ul>
                            </div>
                        </div>
                    </div>
                    <input type="hidden" name="sdNet_id" id="sdNet_id" value="{$data['sdNet_id']}">
                </td>
            </tr>
            <tr>
                <td class="text-right" style="min-width: 160px;width: 160px">产品名称<span class="colorRed">*</span>:</td>
                <td>
                    <div class="col-xs-4">
                        <div class="input-group">
                            <input type="text" class="form-control validate[required]" value="{$data['pro_name']}" name="product" id="product"
                                   placeholder="请输入关键字或空格查询">
                            <div class="input-group-btn">
                                <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                </ul>
                            </div>
                        </div>
                    </div>
                    <input type="hidden" name="product_id" id="product_id" value="{$data['product_id']}">
                    <div class="col-xs-2">
                        <input type="button" class="btn btn-primary" id="selectProduct" value="选择"/>
                    </div>
                </td>
            </tr>
            <tr>
                <td class="text-right" style="min-width: 160px;width: 160px">发运基本单位:</td>
                <td><input type="text" class="form-control" name="fyBasicUnit" id="fyBasicUnit" value="{$data['fyBasicUnit']}"></td>
            </tr>
            <tr>
                <td class="text-right" style="min-width: 160px;width: 160px">数量<span class="colorRed">*</span>:</td>
                <td><input type="text" class="form-control validate[required,custom[integer]]" name="fyNum" id="fyNum" value="{$data['fyNum']}">注：退货可录入负数。
                </td>
            </tr>
            <tr>
                <td class="text-right" style="min-width: 160px;width: 160px">发运开票折后金额<span class="colorRed">*</span>:
                </td>
                <td><input type="text" class="form-control validate[required,custom[number]]" name="fyZheMoney"
                           id="fyZheMoney" value="{$data['fyZheMoney']}">注：退货可录入负数。
                </td>
            </tr>
            <tr>
                <td class="text-right" style="min-width: 160px;width: 160px">毛发运金额:</td>
                <td><input type="text" class="form-control validate[custom[number]]" name="fyMaoMoney" id="fyMaoMoney" value="{$data['fyMaoMoney']}">注：非必填。
                </td>
            </tr>
            <tr>
                <td class="text-right" style="min-width: 160px;width: 160px">净发运金额:</td>
                <td><input type="text" class="form-control validate[custom[number]]" name="fyJingMoney" id="fyJingMoney" value="{$data['fyJingMoney']}">注：非必填。
                </td>
            </tr>
            <tr>
                <td class="text-right" style="min-width: 160px;width: 160px">订单号<span class="colorRed">*</span>:</td>
                <td><input type="text" class="form-control validate[required]" name="orderNumber" id="orderNumber" value="{$data['orderNumber']}"></td>
            </tr>
            <tr>
                <td class="text-right" style="min-width: 160px;width: 160px">发运单号<span class="colorRed">*</span>:</td>
                <td><input type="text" class="form-control validate[required]" name="fyONumber" id="fyONumber" value="{$data['fyONumber']}"></td>
            </tr>
            <tr>
                <td class="text-right" style="min-width: 160px;width: 160px">销售人员<span class="colorRed">*</span>:</td>
                <td>
                    <div class="col-xs-4">
                        <div class="input-group">
                            <input type="text" class="form-control validate[required]" value="{$data['em_name']}" name="salesman" id="salesman"
                                   placeholder="请输入关键字或空格查询">
                            <div class="input-group-btn">
                                <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                </ul>
                            </div>
                        </div>
                    </div>
                    <input type="hidden" name="salesman_id" id="salesman_id" value="{$data['salesman_id']}">
                    <div class="col-xs-2">
                        <input type="button" class="btn btn-primary" id="selectSalesman" value="选择"/>
                    </div>
                </td>
            </tr>
            <tr>
                <td class="text-right" style="min-width: 160px;width: 160px">批号/批次:</td>
                <td><input type="text" class="form-control" name="batchNumber" id="batchNumber" value="{$data['batchNumber']}"></td>
            </tr>
            <tr>
                <td class="text-right" style="min-width: 160px;width: 160px">备注:</td>
                <td><textarea name="des" id="" style="user-select:none;width: 60%"
                              class="form-control validate[maxSize[100]]">{$data['des']}</textarea><span
                        style="vertical-align: bottom;">(100)</span></td>
            </tr>
        </table>
        <div class="text-center padding-10">
            <button class="btn btn-primary" type="button" onclick="submits();">保存并返回</button>
            <span class="lr_5"></span>
            <button class="btn btn-warning back" type="button">返回</button>
        </div>
    </form>
</div>
   <script>
       //网点
       function sdNet(id){
           $("#sdNet").bsSuggest('destroy');
           var catbs = $("#sdNet").bsSuggest({
               url: "{:url('select/netjson')}?keyword=" + id,
               effectiveFieldsAlias: {title: "名称"},
               ignorecase: true,
               showHeader: true,
               showBtn: false,     //不显示下拉按钮
               delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
               idField: "id",
               keyField: "title",
               clearable: true
           });
           //网点名称
           $("#sdNet").bsSuggest('enable');
           catbs.on('onSetSelectValue', function (e, re) {
               $('#sdNet').val(re.key);
               $('#sdNet_id').val(re.id);
               $("#product").bsSuggest('destroy')
               $("#product").bsSuggest({
                   // url: "{:url('select/product')}?keyword="+keyword.id,
                   url: "{:url('select/product')}",
                   effectiveFieldsAlias: {title: "名称"},
                   ignorecase: true,
                   showHeader: true,
                   showBtn: false,     //不显示下拉按钮
                   delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
                   idField: "id",
                   keyField: "title",
                   clearable: true
               }).on('onSetSelectValue', function (e, re) {
                   $('#product').val(re.key);
                   $('#product_id').val(re.id);
               });
           });
       }
      laydate({
        elem:"#fyDate",
        event:"focus"
      })
      $(".back").on("click",function(){
          parent.location.reload();
          parent.layer.close(parent.layer.getFrameIndex(window.name))
      })
       //表单验证
       $('#form_id').validationEngine('attach', {
           promptPosition: 'bottomRight'
       });
       function submits(){
           if($('#form_id').validationEngine('validate')){
               $.post("{:url('Ashippingmanagement/edit')}",$('form').serialize(),function(re){
                   if(re.success){
                           parent.location.reload();
                           parent.layer.close(parent.layer.getFrameIndex(window.name));
                   }else{
                       swal({title: re.msg, text: '', type: "warning"});
                   }
               },'json')
           }
       }
       //弹出经销商树状
       $('#selectSdAgency').click(function () {
           layer.open({
               type: 2,
               area: ['60%', '60%'],
               maxmin: true,
               content: '{:url("Ashippingmanagement/selectJXS")}',
               btn:['确定','关闭'],
               yes:function (i,o) {
                   var a = $(o).find('iframe').contents();
                   var id =  a.find("#renyuan").val();
                   var name =  a.find("#renyuanname").val();
                   if(id){
                       $('#sdAgency').val(name);
                       $('#sdAgency_id').val(id);
                       sdNet(id);
                   }
                   layer.close(i);
               }
           });
           return false
       });

       //搜索经销商
       $("#sdAgency").bsSuggest({
           url: "{:url('select/jxsjson')}",
           /*effectiveFields: ["userName", "shortAccount"],
            searchFields: [ "shortAccount"],*/
           effectiveFieldsAlias: {title: "名称"},
           ignorecase: true,
           showHeader: true,
           showBtn: false,     //不显示下拉按钮
           delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
           idField: "id",
           keyField: "title",
           clearable: true
       }).on('onDataRequestSuccess', function (e, result) {
       }).on('onSetSelectValue', function (e, re) {
           $('#sdAgency').val(re.key);
           $('#sdAgency_id').val(re.id);
           sdNet(re.id);
       });
       //产品单品搜索自动补全
       $("#product").bsSuggest({
           url: "/index.php/index/select/productjson",
           /*effectiveFields: ["userName", "shortAccount"],
            searchFields: [ "shortAccount"],*/
           effectiveFieldsAlias:{title: "名称"},
           ignorecase: true,
           showHeader: true,
           showBtn: false,     //不显示下拉按钮
           delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
           idField: "id",
           keyField: "title",
           clearable: true
       }).on('onSetSelectValue', function (e, keyword, data) {
           console.log(keyword);
           $('#product').val(keyword.key);
           $('#product_id').val(keyword.id);
       });

       //弹出选择产品树状
       $('#selectProduct').on('click',function () {
           layer.open({
               type:2,
               area:['60%','60%'],
               maxmin:true,
               content:'{:url("Ashippingmanagement/selectProduct")}',
               btn:['确定','关闭'],
               yes:function (i,o) {
                   var a = $(o).find('iframe').contents();
                   var id =  a.find("#renyuan").val();
                   var name =  a.find("#renyuanname").val();
                   if(id){
                       $('#product').val(name);
                       $('#product_id').val(id);
                   }
                   layer.close(i);
               }
           });
           return  false
       })
       //销售人员搜索自动补全
       $("#salesman").bsSuggest({
           url: "/index.php/index/apcaiwu/cnamejson",
           /*effectiveFields: ["userName", "shortAccount"],
            searchFields: [ "shortAccount"],*/
           effectiveFieldsAlias:{title: "名称"},
           ignorecase: true,
           showHeader: true,
           showBtn: false,     //不显示下拉按钮
           delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
           idField: "id",
           keyField: "title",
           clearable: true
       }).on('onSetSelectValue', function (e, keyword, data) {
           console.log(keyword);
           $('#salesman').val(keyword.key);
           $('#salesman_id').val(keyword.id);
       });
       //弹出选择销售人树
       $('#selectSalesman').click(function (){
           layer.open({
               type:2,
               area:['60%','60%'],
               title:'销售人',
               maxmin:true,
               content:'/index.php/index/apcaiwu/selectCname',
               btn:['确定','关闭'],
               btnAlign:'c',
               yes:function (i,o) {
                   var id = $(o).find('iframe').contents().find('#renyuan').val()
                   var name = $(o).find('iframe').contents().find('#renyuanname').val()
                   if(id){
                       $('#salesman').val(name);
                       $('#salesman_id').val(id);
                   }
                   layer.close(i)
               }
           });
           return  false
       });

   </script>
{/block}
